import os
import tqdm 
import numpy as np
# 读取txt文件
def load_txt(path):
    with open(path, 'r') as f:
        lines = f.readlines()
    return lines

def concat_txt(dir_path):
    txt = []
    for filename in os.listdir(dir_path):
        path = os.path.join(dir_path, filename)
        lines = load_txt(path)
        txt.append(lines)
    return txt


def main():
    # 读取txt文件
    path = r'3d/position'
    txt = concat_txt(path)
    print(txt)


# 指定要读取的文件夹路径
folder_path = r'3d/position'

# 获取文件夹中所有txt文件的文件名列表
txt_files = [file for file in os.listdir(folder_path) if file.endswith('.txt')]
positions = []

# 逐个读取txt文件的内容并存储到新的txt文件中
for txt_file in tqdm.tqdm(txt_files):
    positions.append(np.loadtxt(os.path.join(folder_path, txt_file)).reshape(-1, 3))


# 保存到新的txt文件中
with open('3d/position.txt', 'a') as f:
    for position in tqdm.tqdm(positions):
        np.savetxt(f, position, fmt='%.6f')



